﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Jim.Core;

public static  class SdkHelper
{
    /// <summary>
    /// 获取请求对象
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public static object GetRequestObject(this ISdkRequest request)
    {
        object obj = request;
        if (request is ISdkCustomRequest customRequest) obj = customRequest.QueryParams();
        return obj;
    }
    /// <summary>
    /// 获取请求对象属性
    /// </summary>
    /// <param name="request"></param>
    /// <param name="attr"></param>
    /// <returns></returns>
    public static bool GetRequestAttr(this ISdkRequest request,out SdkAttribute attr)
    {
        attr = request.GetType().GetCustomAttribute<SdkAttribute>();
        return attr != null;
    }


    /// <summary>
    /// 随机码
    /// </summary>
    /// <returns></returns>
    public static string GetNonce() => Guid.NewGuid().ToString().Replace("-", "");
    /// <summary>
    /// 时间戳
    /// </summary>
    /// <returns></returns>
    public static long GetTimestamp()
    {
        DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        var timeStamp = (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
        return timeStamp;
    }
}